/**
 *
 * @author pquiring
 *
 * Created : Jan 15, 2014
 */

import java.awt.*;
import java.awt.event.*;

import javaforce.*;
import javaforce.media.*;

public class EditNote extends javax.swing.JDialog {

  /**
   * Creates new form EditNote
   */
  public EditNote(java.awt.Frame parent, boolean modal
    , byte note
    , byte volcmd, int volparam
    , byte fxcmd, int fxparam, Music music)
  {
    super(parent, modal);
    initComponents();
    this.music = music;
    if (note == -1) {
      _note.setSelectedIndex(0);
    } else {
      _note.setSelectedIndex(1 + note);
    }
    if ((volcmd & 0x80) == 0x80) {
      global.setSelected(true);
      volcmd &= 0x7f;
    } else {
      global.setSelected(false);
    }
    vol_cmd.setSelectedIndex(volcmd);
    float f = Float.intBitsToFloat(volparam);
    switch (volcmd) {
      case Music.VOLCMD_NONE:
        break;
      case Music.VOLCMD_SET_VOLUME:
      case Music.VOLCMD_SET_VOL_VIBRATE_SPEED:
      case Music.VOLCMD_SET_PAN_VIBRATE_SPEED:
      case Music.VOLCMD_TREMOLO:
      case Music.VOLCMD_PANBRELLO:
        vol_param.setValue((int)(f * 255.0f));
        break;
      case Music.VOLCMD_SET_PANNING:
      case Music.VOLCMD_SLIDE:
      case Music.VOLCMD_PAN_SLIDE:
        vol_param.setValue((int)(((f / 2.0f) + 1.0f) * 255.0f));
        break;
    }
    fx_cmd.setSelectedIndex(fxcmd);
    f = Float.intBitsToFloat(fxparam);
    fxParamPanel.removeAll();
    switch (fxcmd) {
      case Music.FXCMD_NONE:
        break;
      case Music.FXCMD_PORTAMENTO_TO_NOTE:
      case Music.FXCMD_SET_VIBRATE_SPEED:
      case Music.FXCMD_VIBRATO:
        fxParamPanel.add(_1);
        fx_param.setValue((int)(f * 255.0f));
        break;
      case Music.FXCMD_PORTAMENTO:
        fxParamPanel.add(_1);
        fx_param.setValue((int)(((f / 2.0f) + 1.0f) * 255.0f));
        break;
      case Music.FXCMD_TREMOR:
        fxParamPanel.add(_2);
        //short/short
        int s1 = (int)(fxparam >>> 16);
        int s2 = (int)(fxparam & 0xffff);
        fx_param1.setValue(s1 >> 8);
        fx_param2.setValue(s2 >> 8);
        break;
      case Music.FXCMD_SET_INSTRUMENT:
        fxParamPanel.add(_instr);
        loadInstruments();
        fx_instr.setSelectedIndex(fxparam);
        break;
      case Music.FXCMD_DELAY_START:
      case Music.FXCMD_SAMPLE_OFFSET:
      case Music.FXCMD_SET_BPM:
        fxParamPanel.add(_int);
        fx_int.setText("" + fxparam);
        break;
    }
    JFAWT.assignHotKey(this, ok, KeyEvent.VK_ENTER);
    JFAWT.assignHotKey(this, cancel, KeyEvent.VK_ESCAPE);
    setPosition();
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form
   * Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    ok = new javax.swing.JButton();
    cancel = new javax.swing.JButton();
    tabs = new javax.swing.JTabbedPane();
    noteTab = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    _note = new javax.swing.JComboBox();
    volumeTab = new javax.swing.JPanel();
    vol_param = new javax.swing.JSlider();
    vol_cmd = new javax.swing.JComboBox();
    jLabel5 = new javax.swing.JLabel();
    volText = new javax.swing.JLabel();
    global = new javax.swing.JCheckBox();
    effectTab = new javax.swing.JPanel();
    jLabel3 = new javax.swing.JLabel();
    fx_cmd = new javax.swing.JComboBox();
    fxText = new javax.swing.JLabel();
    fxParamPanel = new javax.swing.JPanel();
    fxParamTab = new javax.swing.JTabbedPane();
    _1 = new javax.swing.JPanel();
    fx_param = new javax.swing.JSlider();
    _2 = new javax.swing.JPanel();
    fx_param2 = new javax.swing.JSlider();
    fx_param1 = new javax.swing.JSlider();
    _instr = new javax.swing.JPanel();
    jLabel4 = new javax.swing.JLabel();
    fx_instr = new javax.swing.JComboBox();
    _int = new javax.swing.JPanel();
    jLabel2 = new javax.swing.JLabel();
    fx_int = new javax.swing.JTextField();
    cont = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Edit Note");

    ok.setText("OK");
    ok.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        okActionPerformed(evt);
      }
    });

    cancel.setText("Cancel");
    cancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cancelActionPerformed(evt);
      }
    });

    jLabel1.setText("Note");

    _note.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No Note", "C-0", "C#0", "D-0", "D#0", "E-0", "F-0", "F#0", "G-0", "G#0", "A-0", "A#0", "B-0", "C-1", "C#1", "D-1", "D#1", "E-1", "F-1", "F#1", "G-1", "G#1", "A-1", "A#1", "B-1", "C-2", "C#2", "D-2", "D#2", "E-2", "F-2", "F#2", "G-2", "G#2", "A-2", "A#2", "B-2", "C-3", "C#3", "D-3", "D#3", "E-3", "F-3", "F#3", "G-3", "G#3", "A-3", "A#3", "B-3", "C-4", "C#4", "D-4", "D#4", "E-4", "F-4", "F#4", "G-4", "G#4", "A-4", "A#4", "B-4", "C-5", "C#5", "D-5", "D#5", "E-5", "F-5", "F#5", "G-5", "G#5", "A-5", "A#5", "B-5", "C-6", "C#6", "D-6", "D#6", "E-6", "F-6", "F#6", "G-6", "G#6", "A-6", "A#6", "B-6", "C-7", "C#7", "D-7", "D#7", "E-7", "F-7", "F#7", "G-7", "G#7", "A-7", "A#7", "B-7", "C-8", "C#8", "D-8", "D#8", "E-8", "F-8", "F#8", "G-8", "G#8", "A-8", "A#8", "B-8", "C-9", "C#9", "D-9", "D#9", "E-9", "F-9", "F#9", "G-9", "G#9", "A-9", "A#9", "B-9", " " }));

    javax.swing.GroupLayout noteTabLayout = new javax.swing.GroupLayout(noteTab);
    noteTab.setLayout(noteTabLayout);
    noteTabLayout.setHorizontalGroup(
      noteTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(noteTabLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(_note, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(370, Short.MAX_VALUE))
    );
    noteTabLayout.setVerticalGroup(
      noteTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(noteTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(noteTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(_note, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel1))
        .addContainerGap(127, Short.MAX_VALUE))
    );

    tabs.addTab("Note", noteTab);

    vol_param.setMaximum(255);
    vol_param.setToolTipText("");
    vol_param.setValue(128);
    vol_param.setMinimumSize(new java.awt.Dimension(50, 23));
    vol_param.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        vol_paramStateChanged(evt);
      }
    });

    vol_cmd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "SET_VOLUME", "SET_PANNING", "SLIDE_UP", "SLIDE_DOWN", "PAN_SLIDE_LEFT", "PAN_SLIDE_RIGHT", "SET_VOL_VIBRATE_SPEED", "SET_PAN_VIBRATE_SPEED", "TREMOLO", "PANBRELLO", " " }));
    vol_cmd.addItemListener(new java.awt.event.ItemListener() {
      public void itemStateChanged(java.awt.event.ItemEvent evt) {
        vol_cmdItemStateChanged(evt);
      }
    });

    jLabel5.setText("cmd:");

    volText.setText("Value : ???");

    global.setText("Global");

    javax.swing.GroupLayout volumeTabLayout = new javax.swing.GroupLayout(volumeTab);
    volumeTab.setLayout(volumeTabLayout);
    volumeTabLayout.setHorizontalGroup(
      volumeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(volumeTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(volumeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(vol_param, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .addGroup(volumeTabLayout.createSequentialGroup()
            .addComponent(jLabel5)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(vol_cmd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(volText, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(global)))
        .addContainerGap())
    );
    volumeTabLayout.setVerticalGroup(
      volumeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(volumeTabLayout.createSequentialGroup()
        .addGap(13, 13, 13)
        .addGroup(volumeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel5)
          .addComponent(vol_cmd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(volText)
          .addComponent(global))
        .addGap(11, 11, 11)
        .addComponent(vol_param, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    tabs.addTab("Volume", volumeTab);

    jLabel3.setText("cmd:");

    fx_cmd.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "PORTAMENTO", "PORTAMENTO_TO_NOTE", "SET_VIBRATE_SPEED", "VIBRATO", "TREMOR", "PATTERN_BREAK", "KEY_OFF", "CUT_OFF", "SET_INSTRUMENT", "DELAY_START", "SAMPLE_OFFSET", "SET_BPM", " " }));
    fx_cmd.addItemListener(new java.awt.event.ItemListener() {
      public void itemStateChanged(java.awt.event.ItemEvent evt) {
        fx_cmdItemStateChanged(evt);
      }
    });

    fxText.setText("Value : ???");

    fxParamPanel.setLayout(new java.awt.BorderLayout());

    fx_param.setMaximum(255);
    fx_param.setValue(128);
    fx_param.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        fx_paramStateChanged(evt);
      }
    });

    javax.swing.GroupLayout _1Layout = new javax.swing.GroupLayout(_1);
    _1.setLayout(_1Layout);
    _1Layout.setHorizontalGroup(
      _1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(_1Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(fx_param, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
        .addContainerGap())
    );
    _1Layout.setVerticalGroup(
      _1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(_1Layout.createSequentialGroup()
        .addGap(19, 19, 19)
        .addComponent(fx_param, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    fxParamTab.addTab("1Slider", _1);

    fx_param2.setMaximum(255);
    fx_param2.setValue(128);
    fx_param2.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        fx_param2StateChanged(evt);
      }
    });

    fx_param1.setMaximum(255);
    fx_param1.setValue(128);
    fx_param1.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        fx_param1StateChanged(evt);
      }
    });

    javax.swing.GroupLayout _2Layout = new javax.swing.GroupLayout(_2);
    _2.setLayout(_2Layout);
    _2Layout.setHorizontalGroup(
      _2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(fx_param2, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
      .addComponent(fx_param1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    _2Layout.setVerticalGroup(
      _2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(_2Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(fx_param1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(fx_param2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    fxParamTab.addTab("2Slider", _2);

    jLabel4.setText("Instrument:");

    fx_instr.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "TODO" }));

    javax.swing.GroupLayout _instrLayout = new javax.swing.GroupLayout(_instr);
    _instr.setLayout(_instrLayout);
    _instrLayout.setHorizontalGroup(
      _instrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(_instrLayout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel4)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(fx_instr, 0, 365, Short.MAX_VALUE)
        .addContainerGap())
    );
    _instrLayout.setVerticalGroup(
      _instrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(_instrLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(_instrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(fx_instr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel4))
        .addContainerGap(43, Short.MAX_VALUE))
    );

    fxParamTab.addTab("setInstr", _instr);

    jLabel2.setText("Value:");

    javax.swing.GroupLayout _intLayout = new javax.swing.GroupLayout(_int);
    _int.setLayout(_intLayout);
    _intLayout.setHorizontalGroup(
      _intLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(_intLayout.createSequentialGroup()
        .addComponent(jLabel2)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(fx_int, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
    );
    _intLayout.setVerticalGroup(
      _intLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(_intLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(_intLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(fx_int, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    fxParamTab.addTab("intValue", _int);

    fxParamPanel.add(fxParamTab, java.awt.BorderLayout.CENTER);

    cont.setText("continue");
    cont.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        contActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout effectTabLayout = new javax.swing.GroupLayout(effectTab);
    effectTab.setLayout(effectTabLayout);
    effectTabLayout.setHorizontalGroup(
      effectTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(effectTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(effectTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(effectTabLayout.createSequentialGroup()
            .addComponent(jLabel3)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(fx_cmd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(fxText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(17, 17, 17)
            .addComponent(cont))
          .addComponent(fxParamPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addContainerGap())
    );
    effectTabLayout.setVerticalGroup(
      effectTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(effectTabLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(effectTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel3)
          .addComponent(fx_cmd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(fxText)
          .addComponent(cont))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addComponent(fxParamPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    tabs.addTab("Effect", effectTab);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGap(0, 0, Short.MAX_VALUE)
        .addComponent(cancel)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(ok)
        .addContainerGap())
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(ok)
          .addComponent(cancel))
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
    accepted = true;
    int idx = _note.getSelectedIndex();
    if (idx == 0) {
      note = -1;
    } else {
      idx--;
      note = (byte)idx;
    }
    volcmd = (byte)vol_cmd.getSelectedIndex();
    if (global.isSelected()) volcmd |= 0x80;
    int val = vol_param.getValue();
    float f = ((float)val) / 255.0f;
    switch (volcmd) {
      case Music.VOLCMD_NONE:
        volparam = 0;
        break;
      case Music.VOLCMD_SET_VOLUME:
      case Music.VOLCMD_SET_VOL_VIBRATE_SPEED:
      case Music.VOLCMD_SET_PAN_VIBRATE_SPEED:
      case Music.VOLCMD_TREMOLO:
      case Music.VOLCMD_PANBRELLO:
        volparam = Float.floatToRawIntBits(f);
        break;
      case Music.VOLCMD_SET_PANNING:
      case Music.VOLCMD_SLIDE:
      case Music.VOLCMD_PAN_SLIDE:
        volparam = Float.floatToRawIntBits(f * 2.0f - 1.0f);
        break;
    }
    fxcmd = (byte)fx_cmd.getSelectedIndex();
    switch (fxcmd) {
      case Music.FXCMD_NONE:
        fxparam = 0;
        break;
      case Music.FXCMD_PORTAMENTO_TO_NOTE:
      case Music.FXCMD_SET_VIBRATE_SPEED:
      case Music.FXCMD_VIBRATO:
        fxparam = Float.floatToRawIntBits(((float)fx_param.getValue()) / 255.0f);
        break;
      case Music.FXCMD_PORTAMENTO:
        fxparam = Float.floatToRawIntBits(((float)fx_param.getValue()) / 255.0f * 2.0f - 1.0f);
        break;
      case Music.FXCMD_TREMOR:
        //short/short
        int s1 = fx_param1.getValue() << 8;
        int s2 = fx_param2.getValue() << 8;
        fxparam = s1 << 16 | s2;
        break;
      case Music.FXCMD_SET_INSTRUMENT:
        fxparam = fx_instr.getSelectedIndex();
        break;
      case Music.FXCMD_DELAY_START:
      case Music.FXCMD_SAMPLE_OFFSET:
      case Music.FXCMD_SET_BPM:
        fxparam = JF.atoi(fx_int.getText());
        break;
    }
    dispose();
  }//GEN-LAST:event_okActionPerformed

  private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
    accepted = false;
    dispose();
  }//GEN-LAST:event_cancelActionPerformed

  private void vol_cmdItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_vol_cmdItemStateChanged
    updateVolText();
  }//GEN-LAST:event_vol_cmdItemStateChanged

  private void fx_cmdItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fx_cmdItemStateChanged
    int idx = fx_cmd.getSelectedIndex();
    fxParamPanel.removeAll();
    switch (idx) {
      case Music.FXCMD_NONE:
        break;
      case Music.FXCMD_PORTAMENTO_TO_NOTE:
      case Music.FXCMD_SET_VIBRATE_SPEED:
      case Music.FXCMD_VIBRATO:
        fx_param.setValue(0);
        fxParamPanel.add(_1);
        break;
      case Music.FXCMD_PORTAMENTO:
        fx_param.setValue(0);
        fxParamPanel.add(_1);
        break;
      case Music.FXCMD_TREMOR:
        fx_param1.setValue(0);
        fx_param2.setValue(0);
        fxParamPanel.add(_2);
        break;
      case Music.FXCMD_SET_INSTRUMENT:
        fxParamPanel.add(_instr);
        loadInstruments();
        break;
      case Music.FXCMD_DELAY_START:
      case Music.FXCMD_SAMPLE_OFFSET:
      case Music.FXCMD_SET_BPM:
        fx_int.setText("0");
        fxParamPanel.add(_int);
        break;
    }
    updateFXText();
    repaint();
  }//GEN-LAST:event_fx_cmdItemStateChanged

  private void vol_paramStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_vol_paramStateChanged
    updateVolText();
  }//GEN-LAST:event_vol_paramStateChanged

  private void fx_paramStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_fx_paramStateChanged
    updateFXText();
  }//GEN-LAST:event_fx_paramStateChanged

  private void fx_param2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_fx_param2StateChanged
    updateFXText();
  }//GEN-LAST:event_fx_param2StateChanged

  private void fx_param1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_fx_param1StateChanged
    updateFXText();
  }//GEN-LAST:event_fx_param1StateChanged

  private void contActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contActionPerformed
    switch (fx_cmd.getSelectedIndex()) {
      default:
        fx_param.setValue(0);
        break;
      case Music.FXCMD_PORTAMENTO:
        fx_param.setValue(128);
        break;
      case Music.FXCMD_TREMOR:
        fx_param1.setValue(0);
        fx_param2.setValue(0);
        break;
    }
  }//GEN-LAST:event_contActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel _1;
  private javax.swing.JPanel _2;
  private javax.swing.JPanel _instr;
  private javax.swing.JPanel _int;
  private javax.swing.JComboBox _note;
  private javax.swing.JButton cancel;
  private javax.swing.JButton cont;
  private javax.swing.JPanel effectTab;
  private javax.swing.JPanel fxParamPanel;
  private javax.swing.JTabbedPane fxParamTab;
  private javax.swing.JLabel fxText;
  private javax.swing.JComboBox fx_cmd;
  private javax.swing.JComboBox fx_instr;
  private javax.swing.JTextField fx_int;
  private javax.swing.JSlider fx_param;
  private javax.swing.JSlider fx_param1;
  private javax.swing.JSlider fx_param2;
  private javax.swing.JCheckBox global;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JPanel noteTab;
  private javax.swing.JButton ok;
  private javax.swing.JTabbedPane tabs;
  private javax.swing.JLabel volText;
  private javax.swing.JComboBox vol_cmd;
  private javax.swing.JSlider vol_param;
  private javax.swing.JPanel volumeTab;
  // End of variables declaration//GEN-END:variables

  public boolean accepted;
  public byte note;
  public byte volcmd;
  public int volparam;
  public byte fxcmd;
  public int fxparam;
  private Music music;

  private void setPosition() {
    Dimension d = getSize();
    Rectangle s = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    if ((d.width > s.width) || (d.height > s.height)) {
      if (d.width > s.width) d.width = s.width;
      if (d.height > s.height) d.height = s.height;
      setSize(d);
    }
    setLocation(s.width/2 - d.width/2, s.height/2 - d.height/2);
  }

  private void updateVolText() {
    int idx = vol_cmd.getSelectedIndex();
    int val = vol_param.getValue();
    float f = ((float)val) / 255.0f;
    volText.setText(String.format("Value : %1.3f", f));
  }

  private void updateFXText() {
    int idx = fx_cmd.getSelectedIndex();
    switch (idx) {
      default:
      case Music.FXCMD_NONE:
        fxText.setText("Value:");
        break;
      case Music.FXCMD_PORTAMENTO_TO_NOTE:
      case Music.FXCMD_SET_VIBRATE_SPEED:
      case Music.FXCMD_VIBRATO:
        if (fx_param.getValue() == 0) {
          fxText.setText("Value: continue");
        } else {
          fxText.setText("Value:" + String.format("%1.3f", ((float)fx_param.getValue()) / 255.0f));
        }
        break;
      case Music.FXCMD_PORTAMENTO:
        if (fx_param.getValue() == 128) {
          fxText.setText("Value: continue");
        } else {
          fxText.setText("Value:" + String.format("%1.3f", ((float)fx_param.getValue()) / 255.0f * 2.0f - 1.0f));
        }
        break;
      case Music.FXCMD_TREMOR:
        //short/short
        int s1 = (int)(((float)fx_param1.getValue()) / 255.0f * (65535.0f / 44100.0f * 1000.0f));
        int s2 = (int)(((float)fx_param2.getValue()) / 255.0f * (65535.0f / 44100.0f * 1000.0f));
        if (s1 == 0 && s2 == 0) {
          fxText.setText("Value: continue");
        } else {
          fxText.setText(String.format("Value:on %dms, off %dms", s1, s2));
        }
        break;
      case Music.FXCMD_SET_INSTRUMENT:
        fxText.setText("Value:" + fx_instr.getSelectedItem());
        break;
      case Music.FXCMD_DELAY_START:
      case Music.FXCMD_SAMPLE_OFFSET:
      case Music.FXCMD_SET_BPM:
        fxText.setText("Value:" + JF.atoi(fx_int.getText()));
        break;
    }
  }

  public void loadInstruments() {
    fx_instr.removeAllItems();
    int cnt = music.song.instruments.size();
    for(int a=0;a<cnt;a++) {
      fx_instr.addItem(music.song.instruments.get(a).name);
    }
  }
}
